package com.michael.aop.customer.advisor;

import com.michael.aop.annotation.Log;
import com.michael.aop.customer.interceptor.LogInterceptor;
import org.aopalliance.aop.Advice;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMethodMatcher;
import org.springframework.context.annotation.Role;
import org.springframework.stereotype.Component;

@Role(2)
@Component
public class LoggingAdvisor implements PointcutAdvisor {
    public Pointcut getPointcut() {
        return new Pointcut() {
            public ClassFilter getClassFilter() {
                return ClassFilter.TRUE;
            }

            public MethodMatcher getMethodMatcher() {
                return new AnnotationMethodMatcher(Log.class);
            }
        };
    }

    public Advice getAdvice() {
        return new LogInterceptor();
    }

    public boolean isPerInstance() {
        return false;
    }
}
